﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using MakeIT.MiraPark.Negocios;
using Microsoft.Reporting.WinForms;
using MakeIT.MiraPark.Apresentacao.Rotinas;
using MakeIT.MiraPark.Apresentacao.Rotinas.DS_RotinasTableAdapters;

namespace MiraPark{

    public partial class FormReportDiario : Form
    {
        DateTime dtRef = DateTime.Today;

        public FormReportDiario()
        {
            InitializeComponent();
        }

        private void FormTesteRelatorio_Load(object sender, EventArgs e)
        {
            reportViewer1.LocalReport.SubreportProcessing +=
                    new SubreportProcessingEventHandler(Mensal_SubreportProcessingEventHandler);

            this.reportViewer1.RefreshReport();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        public void setDataSource(DateTime dtRef)
        {
            this.dtRef = dtRef;
            List<ReportParameter> rps = new List<ReportParameter>();
            rps.Add(new ReportParameter("Empresa", ModelBO.getEmpresa(int.Parse(ModelBO.getParametro("Empresa Ativa"))).nome));
            rps.Add(new ReportParameter("MesAno",dtRef.ToString("dd/MM/yyyy")));
            rps.Add(new ReportParameter("Tipo","Diário"));
            this.reportViewer1.LocalReport.SetParameters(rps);
        }

        private void Mensal_SubreportProcessingEventHandler(object sender, SubreportProcessingEventArgs e)
        {
            
            DateTime dtIni = dtRef;
            DateTime dtFim = dtRef;

            if (e.ReportPath.Equals("ReportAletasPendentes"))
            {
                alertas_pendentesTableAdapter apta = new alertas_pendentesTableAdapter();
                DS_Rotinas.alertas_pendentesDataTable apdt = new DS_Rotinas.alertas_pendentesDataTable();
                apdt = apta.GetData();
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)apdt));
            }
            if (e.ReportPath.Equals("ReportAlertasExecutados"))
            {
                alertas_executadosTableAdapter apta = new alertas_executadosTableAdapter();
                DS_Rotinas.alertas_executadosDataTable apdt = new DS_Rotinas.alertas_executadosDataTable();
                apdt = apta.GetData(dtIni, dtFim);
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)apdt));
            }
            if (e.ReportPath.Equals("ReportMovFinCab"))
            {
                movimentos_financeiros_cabineTableAdapter mfta = new movimentos_financeiros_cabineTableAdapter();
                DS_Rotinas.movimentos_financeiros_cabineDataTable mfdt = new DS_Rotinas.movimentos_financeiros_cabineDataTable();
                mfdt = mfta.GetData(dtIni, dtFim);
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable) mfdt));
            }
            if (e.ReportPath.Equals("ReportRec"))
            {
                recebimentoTableAdapter rta = new recebimentoTableAdapter();
                DS_Rotinas.recebimentoDataTable rdt = new DS_Rotinas.recebimentoDataTable();
                rdt = rta.GetData(dtIni, dtFim);
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)rdt));
            }
            if (e.ReportPath.Equals("ReportRecebimentoAberto"))
            {
                recebimentoAbertoTableAdapter rata = new recebimentoAbertoTableAdapter();
                DS_Rotinas.recebimentoAbertoDataTable radt = new DS_Rotinas.recebimentoAbertoDataTable();
                radt = rata.GetData();
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)radt));
            }
            if (e.ReportPath.Equals("ReportRecebimentoConvenio"))
            {
                recebimentoConvenioTableAdapter rta = new recebimentoConvenioTableAdapter();
                DS_Rotinas.recebimentoConvenioDataTable rdt = new DS_Rotinas.recebimentoConvenioDataTable();
                rdt = rta.GetData(dtIni, dtFim);
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)rdt));
            }
            if (e.ReportPath.Equals("ReportRecebimentoMensalista"))
            {
                recebimentoMensalistaTableAdapter rta = new recebimentoMensalistaTableAdapter();
                DS_Rotinas.recebimentoMensalistaDataTable rdt = new DS_Rotinas.recebimentoMensalistaDataTable();
                rdt = rta.GetData(dtIni, dtFim);
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)rdt));
            }
            if (e.ReportPath.Equals("ReportRecebimentoDiversos"))
            {
                recebimentoDiversosTableAdapter rta = new recebimentoDiversosTableAdapter();
                DS_Rotinas.recebimentoDiversosDataTable rdt = new DS_Rotinas.recebimentoDiversosDataTable();
                rdt = rta.GetData(dtIni, dtFim);
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)rdt));
            }
            if (e.ReportPath.Equals("ReportPagamento"))
            {
                pagamentoTableAdapter rta = new pagamentoTableAdapter();
                DS_Rotinas.pagamentoDataTable rdt = new DS_Rotinas.pagamentoDataTable();
                rdt = rta.GetData(dtIni, dtFim);
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)rdt));
            }
            if (e.ReportPath.Equals("ReportPagamentoAberto"))
            {
                pagamentoAbertoTableAdapter rta = new pagamentoAbertoTableAdapter();
                DS_Rotinas.pagamentoAbertoDataTable rdt = new DS_Rotinas.pagamentoAbertoDataTable();
                rdt = rta.GetData();
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)rdt));
            }
            if (e.ReportPath.Equals("ReportPendencia"))
            {
                pendenciaAbertoTableAdapter rta = new pendenciaAbertoTableAdapter();
                DS_Rotinas.pendenciaAbertoDataTable rdt = new DS_Rotinas.pendenciaAbertoDataTable();
                rdt = rta.GetData();
                e.DataSources.Add(new ReportDataSource(e.DataSourceNames[0], (DataTable)rdt));
            }

        }


    }
}
